package org.reliablesource.prism.ui.workbench.actions;

/**
 *
 *  Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 *
 *	Created on: Mar 11, 2006
 *	@author Dennis Park <a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 */

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.reliablesource.prism.ui.popup.actions.DeletePrismElementAction;

public class DeleteElementAction implements IObjectActionDelegate {
	IWorkbenchWindow window;
	public static String ID = "IPrismElement.Contribution.DeleteElementAction";
	IStructuredSelection currentSelection;
	IWorkbenchPart currentPart;
	DeletePrismElementAction deleteAction;
	
	public DeleteElementAction(){
		deleteAction = new DeletePrismElementAction();
		deleteAction.setAccelerator(SWT.DEL);
	}
	
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		currentPart = targetPart;

		if(action.getImageDescriptor() == null)
			action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
	}

	public void run(IAction _action) {
		if(!_action.isEnabled())
			return;
		deleteAction.run();
	}

	public void selectionChanged(IAction action, ISelection _selection) {
		
		action.setEnabled(false);
		
		if(null == _selection)
				return;

		boolean _enabled = deleteAction.setSelection(_selection);
		action.setEnabled(_enabled);
	}
	
	public String getId() {
		return ID;
	}
}
